<?php
/**
 * Created by PhpStorm.
 * User: guokunsheng
 * Date: 2024/8/14
 * Time: 下午4:04
 */

namespace app\web\controller;

use think\Controller;

/**
 * 脉轮测试
 * Class Chakra
 * @package app\web\controller
 */
class Chakra extends Controller
{
    public function index()
    {
        $typeList = [
            0 => ['id' => 0, 'name' => '海底轮'],
            1 => ['id' => 1, 'name' => '本我轮'],
            2 => ['id' => 2, 'name' => '脐  轮'],
            3 => ['id' => 3, 'name' => '心  轮'],
            4 => ['id' => 4, 'name' => '喉  轮'],
            5 => ['id' => 5, 'name' => '三眼轮'],
            6 => ['id' => 6, 'name' => '顶  轮'],
        ];
        /**
         * id
         *  问题ID
         * question
         *  问题
         * type
         *  0=>海底轮（Root）,1=>本我轮（Sacral）,2=>脐轮（Navel）,
         *  3=>心轮（Heart）,4=>喉轮（Throat）,5=>三眼轮（Third Eye）,6=>顶轮（Crown）
         */
        $questionList = [
            [
                'id' => 1,
                'question' => '你总是很有安全感？',
                'type' => 0,
                'checked' => 3,
            ],
            [
                'id' => 2,
                'question' => '你是否通常觉得活在当下，生活十分踏实？',
                'type' => 0,
                'checked' => 3,
            ],
            [
                'id' => 3,
                'question' => '你担心自己的财务状况和家宅的安全？',
                'type' => 0,
                'checked' => 3,
            ],
            [
                'id' => 4,
                'question' => '你有自律的习惯？',
                'type' => 0,
                'checked' => 3,
            ],
            [
                'id' => 5,
                'question' => '你觉得不论在哪里，都感到很自在？',
                'type' => 0,
                'checked' => 3,
            ],
            [
                'id' => 6,
                'question' => '你通常觉得你的身体内是有灵魂的吗？',
                'type' => 0,
                'checked' => 3,
            ],
            [
                'id' => 7,
                'question' => '是否经常有一些情况你极力想避免？',
                'type' => 0,
                'checked' => 3,
            ],
            [
                'id' => 8,
                'question' => '你容易紧张或会尽量避免让你紧张的情况发生？',
                'type' => 0,
                'checked' => 3,
            ],
            [
                'id' => 9,
                'question' => '你是否很依赖于某些人或事？',
                'type' => 1,
                'checked' => 3,
            ],
            [
                'id' => 10,
                'question' => '你是否觉得人和人之间的相处很容易产生信任？',
                'type' => 1,
                'checked' => 3,
            ],
            [
                'id' => 11,
                'question' => '你能自由地表达对性方面的感觉？',
                'type' => 1,
                'checked' => 3,
            ],
            [
                'id' => 12,
                'question' => '你对于亲密关系和肉体欲望，都感觉是很自然的事情，也不会因此觉得羞愧？',
                'type' => 1,
                'checked' => 3,
            ],
            [
                'id' => 13,
                'question' => '你是个非常情绪化和热情的人？',
                'type' => 1,
                'checked' => 3,
            ],
            [
                'id' => 14,
                'question' => '你倾向于隐藏情绪，不显露表情？',
                'type' => 1,
                'checked' => 3,
            ],
            [
                'id' => 15,
                'question' => '你倾向把发生在自己身上的事当作学习的过程？',
                'type' => 1,
                'checked' => 3,
            ],
            [
                'id' => 16,
                'question' => '你对于自己的本能冲动感到羞耻？',
                'type' => 1,
                'checked' => 3,
            ],

            [
                'id' => 17,
                'question' => '你说话时的声音洪亮清晰？',
                'type' => 2,
                'checked' => 3,
            ],
            [
                'id' => 18,
                'question' => '你总是有掌控局势的强烈欲望？',
                'type' => 2,
                'checked' => 3,
            ],
            [
                'id' => 19,
                'question' => '处于团体中，你感觉可以掌控事情的发展？',
                'type' => 2,
                'checked' => 3,
            ],
            [
                'id' => 20,
                'question' => '你跟团队合作感到很轻松，觉得这比单打独斗好太多了？',
                'type' => 2,
                'checked' => 3,
            ],
            [
                'id' => 21,
                'question' => '你很有自信？',
                'type' => 2,
                'checked' => 3,
            ],
            [
                'id' => 22,
                'question' => '你行事比较倾向于事前规划而非随遇而安？',
                'type' => 2,
                'checked' => 3,
            ],
            [
                'id' => 23,
                'question' => '你能在必要时积极主动？',
                'type' => 2,
                'checked' => 3,
            ],
            [
                'id' => 24,
                'question' => '你对于你所想要的事物会采取行动？',
                'type' => 2,
                'checked' => 3,
            ],

            [
                'id' => 25,
                'question' => '你喜爱身边大多数的人？',
                'type' => 3,
                'checked' => 3,
            ],
            [
                'id' => 26,
                'question' => '你需要时常和人联系，以保证自己不会太孤独？',
                'type' => 3,
                'checked' => 3,
            ],
            [
                'id' => 27,
                'question' => '你是一个天生就很友善的人？',
                'type' => 3,
                'checked' => 3,
            ],
            [
                'id' => 28,
                'question' => '你努力追求人与人关系的和谐？',
                'type' => 3,
                'checked' => 3,
            ],
            [
                'id' => 29,
                'question' => '你具有热情和同理心，可以容易延伸至自我和他人？',
                'type' => 3,
                'checked' => 3,
            ],
            [
                'id' => 30,
                'question' => '你是否倾向被动，感到寂寞，或与他人刻意保持距离？',
                'type' => 3,
                'checked' => 3,
            ],
            [
                'id' => 31,
                'question' => '你总是对他人付出太多以至于忘记了自己？',
                'type' => 3,
                'checked' => 3,
            ],
            [
                'id' => 32,
                'question' => '如果你和他人有冲突，你会考虑到他人的感受？',
                'type' => 3,
                'checked' => 3,
            ],

            [
                'id' => 33,
                'question' => '你在社交上有时候会比较被动和犹豫不决？',
                'type' => 4,
                'checked' => 3,
            ],
            [
                'id' => 34,
                'question' => '你善于沟通，能倾听也能善于表达？',
                'type' => 4,
                'checked' => 3,
            ],
            [
                'id' => 35,
                'question' => '你很难表达自己的感觉，并且很少说话？',
                'type' => 4,
                'checked' => 3,
            ],
            [
                'id' => 36,
                'question' => '你喜欢透过某种形式或创作（音乐，绘画，唱歌，健身或其他）表达情绪？',
                'type' => 4,
                'checked' => 3,
            ],
            [
                'id' => 37,
                'question' => '你对于表达示好的对象很小心，以免受到伤害？',
                'type' => 4,
                'checked' => 3,
            ],
            [
                'id' => 38,
                'question' => '你容易毫无保留地表达自己的情感？',
                'type' => 4,
                'checked' => 3,
            ],
            [
                'id' => 39,
                'question' => '你善于写作以进行沟通？',
                'type' => 4,
                'checked' => 3,
            ],
            [
                'id' => 40,
                'question' => '你算是一个e人，总能滔滔不绝地聊天？',
                'type' => 4,
                'checked' => 3,
            ],

            [
                'id' => 41,
                'question' => '你通常依赖他人的洞察力？',
                'type' => 5,
                'checked' => 3,
            ],
            [
                'id' => 42,
                'question' => '你很依赖直觉？',
                'type' => 5,
                'checked' => 3,
            ],
            [
                'id' => 43,
                'question' => '你能觉察你的喜好、厌恶和需求？',
                'type' => 5,
                'checked' => 3,
            ],
            [
                'id' => 44,
                'question' => '你出现过在现实生活中回想梦境的感觉，仿佛这一幕曾经出现过？',
                'type' => 5,
                'checked' => 3,
            ],
            [
                'id' => 45,
                'question' => '你喜欢无拘无束的幻想？',
                'type' => 5,
                'checked' => 3,
            ],
            [
                'id' => 46,
                'question' => '如果要把一件复杂的事情视觉化，你会觉得这是件有点困难的事情',
                'type' => 5,
                'checked' => 3,
            ],
            [
                'id' => 47,
                'question' => '你善于用语言，符号和概念进行思考？',
                'type' => 5,
                'checked' => 3,
            ],
            [
                'id' => 48,
                'question' => '你对于未来有愿景或期待？',
                'type' => 5,
                'checked' => 3,
            ],

            [
                'id' => 49,
                'question' => '你觉得所谓巧合通常是有无形的力量在指挥着这一切，而非全是随机发生？',
                'type' => 6,
                'checked' => 3,
            ],
            [
                'id' => 50,
                'question' => '你时常觉得自己第六感很强？',
                'type' => 6,
                'checked' => 3,
            ],
            [
                'id' => 51,
                'question' => '你感觉到完整的自觉意识？',
                'type' => 6,
                'checked' => 3,
            ],
            [
                'id' => 52,
                'question' => '你觉得和身边所有围绕你的事物或宇宙间有某种联系？',
                'type' => 6,
                'checked' => 3,
            ],
            [
                'id' => 53,
                'question' => '你感觉自己的背后其实有一股无形的力量在支撑和跟随着你？',
                'type' => 6,
                'checked' => 3,
            ],
            [
                'id' => 54,
                'question' => '你对所有发生在你身上的事情都觉得能够接受？',
                'type' => 6,
                'checked' => 3,
            ],
            [
                'id' => 55,
                'question' => '你很有创造性？',
                'type' => 6,
                'checked' => 3,
            ],
            [
                'id' => 56,
                'question' => '你常常有好的、创新的点子？',
                'type' => 6,
                'checked' => 3,
            ],

        ];

//        echo json_encode($questionList, JSON_UNESCAPED_UNICODE);exit;

        if ($this->request->isPost())
        {
            $res = [
                ['score' => 0, 'status' => '未开启'],
                ['score' => 0, 'status' => '未开启'],
                ['score' => 0, 'status' => '未开启'],
                ['score' => 0, 'status' => '未开启'],
                ['score' => 0, 'status' => '未开启'],
                ['score' => 0, 'status' => '未开启'],
                ['score' => 0, 'status' => '未开启'],
            ];
            $formData = $this->request->post();
            foreach ($formData as $k1 => $v1)
            {
                $v1 -= 3;
                $qid = (int)substr($k1, 1);
                foreach ($questionList as $k2 => $v2)
                {
                    if ($qid === $v2['id'])
                    {
                        $questionList[$k2]['checked'] = $v1;
                        $res[$v2['type']]['score'] += $v1;
                        break;
                    }
                }
            }
//            echo '<h3><a class="btn" href="/web/chakra/index">返回</a></h3>';
            foreach ($res as $k3 => $v3)
            {
                $s = (int)($v3['score'] / 16 * 100);
                //封闭（Closed/Blocked）=负100%-负50%；
                //不活跃（Inactive/Blocked）=负51%-0；
                //已开启（Active/Open/Balanced）=1-50%；
                //过度活跃（Overactive/Excessive）=51%-100%
                if ($s > 50)
                {
                    $res[$k3]['status'] = '过度活跃';
                } elseif ($s > 0)
                {
                    $res[$k3]['status'] = '已开启';
                } elseif ($s > -50)
                {
                    $res[$k3]['status'] = '不活跃';
                } else
                {
                    $res[$k3]['status'] = '封闭';
                }
                $res[$k3]['name'] = $typeList[$k3]['name'];
                $res[$k3]['score'] = $s . '%';

                echo $res[$k3]['name'] . '：' . $res[$k3]['status'] . '（' . $res[$k3]['score'] . '）<br/>';
            }
        }

        shuffle($questionList);

        return $this->fetch('', [
            'question_data' => $questionList,
            'type_list' => $typeList,
        ]);
    }
}
